<!--
 * @FileDescription: 梯控 - 列表组件
 * @Author: Ronghao Zhu
 * @CreateTime: 2020/09/07 星期一
 * @LastEditors: Ronghao Zhu
 * @LastEditTime: 2020/09/07
-->

<template>
  <div class="wrap-remotecontroller-list" :class="{ 'status-disabled':formInline.status==5 }">
    <el-table ref="mainTable" style="width: 100%" :data="tableData.data" :show-header="false">
      <el-table-column width="120" align="center" class-name="cell-relative">
        <template slot-scope="scope">
          <el-image
            v-if="scope.row.categoryPicUrl"
            fit="cover"
            lazy
            :src="scope.row.categoryPicUrl.split(',')[0]"
            :preview-src-list="[scope.row.categoryPicUrl.split(',')]"
            style="width: 100px; height: 100px"
          ></el-image>
          <div v-if="scope.row.realTimeStatus==10" class="pic-tag" :class="{'tag-red':scope.row.realTimeStatus==10}">触发</div>
        </template>
      </el-table-column>

      <el-table-column>
        <template slot-scope="scope">
          <p>名称：{{ scope.row.name }}</p>
          <p>单位：{{ scope.row.organizationName }}</p>
          <p>位置：{{ scope.row.location }}</p>
        </template>
      </el-table-column>
      <el-table-column width="100" align="right">
        <template slot-scope="scope">
          <el-button @click="operate(scope.row,1)" size="mini" type="danger" plain>启用</el-button>
          <el-button @click="operate(scope.row,0)" size="mini" type="primary" plain style="margin-top:10px;">关闭</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      @size-change="_pageSize => getList(1, _pageSize)"
      @current-change="_pageIndex => getList(_pageIndex)"
      :current-page="formInline.pageIndex + 1"
      :page-sizes="[10, 50, 100]"
      :page-size="formInline.pageSize"
      :total="tableData.total"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>

<script>
import util from '@/utils/util'

export default {
  name: 'ElevatorControllerList',
  components: {},
  props: {
    formInline: {
      type: Object,
      required: true,
    },
    tableData: {
      type: Object,
      required: true,
    },
    getList: {
      type: Function,
      required: true,
    },
    operate: {
      type: Function,
      required: true,
    },
  },
  data() {
    return {
      multipleSelection: [], // 选中的选项
      selectedNum: 0, // 选中的个数
      allSelected: false, // 是否全部选中
      imgUrl: '../../../assets/images/ladderControl/ladder_control.png',
    }
  },
  watch: {
    multipleSelection(val) {
      if (val) this.selectedNum = val.length || 0
      if (val.length === 0) this.allSelected = false
    },
  },
  created() {},
  methods: {
    /* 处理选中的值 */
    handleSelectionChange(val) {
      this.multipleSelection = val
      if (val && this.multipleSelection && this.tableData.data) {
        this.multipleSelection.length === this.tableData.data.length
          ? (this.allSelected = true)
          : (this.allSelected = false)
      }
    },
    /* 全选 */
    toggleSelection(rows) {
      this.allSelected
        ? this.$refs.mainTable.toggleAllSelection()
        : this.$refs.mainTable.clearSelection()
    },
    /* 查看监控 */
    openMonitor(row) {
      util.defaultShowVideo(row.video[0])
      // util.rowShowVedio(row.video[0])
    },
  },
}
</script>

<style lang="scss">
.wrap-remotecontroller-list {
  &.status-disabled {
    .cell {
      .el-checkbox {
        display: none;
      }
    }
  }
  .el-table {
    max-height: 570px;
    overflow: auto;
  }
  .cell {
    position: relative;
    .pic-tag {
      position: absolute;
      top: 0;
      left: 10px;
      padding: 0 5px;
      font-size: 12px;
      color: #fff;
      opacity: 0.9;
      border-radius: 0 0 5px 0;
    }
    .tag-red {
      background-color: #f56c6c;
    }
    .tag-grey {
      background-color: grey;
    }
    .tag-green {
      background-color: #67c23a;
    }
    .acquiesce-image {
      width: 100px;
      height: 100px;
      background-image: '../../../assets/images/ladderControl/ladder_control.png';
    }
  }
}
</style>
